package com.xinhe.web.session;

import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.ObjectUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UserSessionView {
    private String key;
    private String token;
    private Long userId;
    private Map<String, String> extendValue;
    private List<RoleView> roles;
    private List<MenuView> menus;

    public UserSessionView() {}

    public UserSessionView(Long userId, Long roleId) {
        this.userId = userId;
        this.roles = new ArrayList<>();
        this.roles.add(new RoleView(roleId));
    }

    public UserSessionView(Long userId, List<RoleView> roles) {
        this.userId = userId;
        this.roles = roles;
    }

    public UserSessionView(Long userId, List<RoleView> roles, List<MenuView> menus) {
        this.userId = userId;
        this.roles = roles;
        this.menus = menus;
    }

    public String putExtendValue(String key, String value) {
        if (null == this.extendValue) {
            this.extendValue = new HashMap<>();
        }
        return this.extendValue.put(key, value);
    }

    public String getExtendValue(String key, String defaultValue) {
        if (null == this.extendValue) {
            return null;
        }
        return (String) ObjectUtils.defaultIfNull(this.extendValue.get(key), defaultValue);
    }

    public String getKey() {
        return this.key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getToken() {
        return this.token;
    }

    void setToken(String token) {
        this.token = token;
    }

    public Long getUserId() {
        return this.userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Map<String, String> getExtendValue() {
        return this.extendValue;
    }

    public void setExtendValue(Map<String, String> extendValue) {
        this.extendValue = extendValue;
    }

    public List<RoleView> getRoles() {
        return this.roles;
    }

    public void setRoles(List<RoleView> roles) {
        this.roles = roles;
    }

    public List<MenuView> getMenus() {
        return this.menus;
    }

    public void setMenus(List<MenuView> menus) {
        this.menus = menus;
    }

    public static class MenuView {
        private Long id;
        private String path;

        public Long getId() {
            return this.id;
        }
        public void setId(Long id) {
            this.id = id;
        }
        public String getPath() {
            return this.path;
        }
        public void setPath(String path) {
            this.path = path;
        }
    }

    public static class RoleView {
        @ApiModelProperty("标识")
        private Long id;
        @ApiModelProperty("等级")
        private Integer level;
        @ApiModelProperty("名称")
        private String name;
        @ApiModelProperty("备注")
        private String remark;


        public RoleView() {}
        public RoleView(Long id) {
            this.id = id;
        }
        public Long getId() {
            return this.id;
        }
        public void setId(Long id) {
            this.id = id;
        }
        public Integer getLevel() {
            return this.level;
        }
        public void setLevel(Integer level) {
            this.level = level;
        }
        public String getName() {
            return this.name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public String getRemark() {
            return this.remark;
        }
        public void setRemark(String remark) {
            this.remark = remark;
        }
    }

}
